package command;

import guimessage.Connect;

import javax.swing.JTextField;

import controller.ContactsTable;
import controller.GUIController;

public class LogOn implements ICommand {
	protected JTextField tloginField;
	protected GUIController guicontroller;
	
	public LogOn(JTextField tloginField)
	{
		this.tloginField = tloginField;
		this.guicontroller = GUIController.getInstance();
	}
	
	public void execute()
	{
		String username = tloginField.getText();
		
		if(username.length() != 0)
		{
			ContactsTable.setLocalUsername(username);
			guicontroller.messages.add( new Connect( username ) );
			(new NextPanel()).goChatScreen();
		}
	}
}